package com.linjiang.design.decorator;

//装饰者模式
//在不改变原有对象的基础上，将功能附加到对象上
public class DecoratorTest {

    public static void main(String[] args) {
        Component component = new ConcreteDecorator1(new ConcreteComponent());
        Component component2 = new ConcreteDecorator2(component);
        component2.operation();
    }
}

interface Component{
    void operation();
}

class ConcreteComponent implements Component{

    @Override
    public void operation() {
        System.out.println("拍照");
    }
}

//装饰者
abstract class Decorator implements Component{
    Component component;

    public Decorator(Component component) {
        this.component = component;
    }
}

class ConcreteDecorator1 extends Decorator{

    public ConcreteDecorator1(Component component) {
        super(component);
    }

    @Override
    public void operation() {
        //附加功能
        System.out.println("美颜");
        //调用原先组件的方法
        component.operation();
    }
}

class ConcreteDecorator2 extends Decorator{

    public ConcreteDecorator2(Component component) {
        super(component);
    }

    @Override
    public void operation() {
        //附加功能
        System.out.println("滤镜");
        //调用原先组件的方法
        component.operation();
    }
}
